/*
 * @Author: szx
 * @Date: 2022-03-10 15:03:48
 * @LastEditTime: 2022-03-10 15:06:26
 * @Description:
 * @FilePath: \leetcode\1-99\77\77_2.js
 */
/**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
var combine = function (n, k) {
    const res = [];
    const backtrack = (arr, index) => {
        if (arr.length >= k) {
            if (arr.length == k) res.push(Array.from(arr));
            return;
        }
        for (let i = index; i <= n; i++) {
            arr.push(i);
            backtrack(arr, i + 1);
            arr.pop();
        }
    };
    backtrack([], 1);
    return res;
};
console.log(combine(1, 1));
